package com.baidu.kshpt.rabbitmq;

import com.baidu.kshpt.service.TestService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.Random;

@Component
@RabbitListener(queues = "testDirectQueue")
public class RabbitMqConsumer {
    @Autowired
    private TestService testService;

    @Value("${haha.xixi}")
    private String haha;


    @RabbitHandler
    public void process(Map testMessage) {

        Random random = new Random();
        System.out.println(haha);
        for (int i = 0; i < 33333; i++) {
            int zz = i + i;
        }
        int id = (int) Math.floor(random.nextDouble() * 1000000.0);
        String string = testMessage.get("String").toString();
        String anInt = testMessage.get("int").toString();
        testService.insertTest(id, string, anInt);
        //System.out.println(Thread.currentThread().getName() + "收到消息" + testMessage.toString());
    }

}
